package com.lisp.springframework.core.aop.aspectj;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

/** 
 * AspectJ的切面，注意不能加@Component
 * */
@Aspect
public class AJSayHelloAspect {
    
    @Pointcut(value = "within(com.lisp.springframework.core.aop.aspectj..*) && execution(public * sayHello(..)) && args(name,..)", argNames = "name")
    public void sayHello(String name) { }
    
    @After(value = "sayHello(name)", argNames = "name") 
    public void afterSayHello(String name) { 
        System.out.println("--------- after sayHello " + name + "-------------"); 
    }
    
    @Around(value = "within(com.lisp.springframework.core.aop.aspectj..*) && execution(public * sayHello(..)) && args(name,..)", argNames = "name")
    public Object aroundSayHello(ProceedingJoinPoint pjp, String name) throws Throwable {
        Object retVal = pjp.proceed();
        System.out.println("--------- aroud sayHello " + name + "-------------"); 
        return retVal;
    }
    
    @Before(value = "within(com.lisp.springframework.core.aop.aspectj..*) && execution(public * innerInvoke(..))")
    public void beforeInnerInvoke() throws Throwable {
        System.out.println("--------- before innerInvoke -------------");
    }
}
